package com.apps.member.script;


import com.apps.goods.model.po.KupaGoods;
import com.apps.member.event.sMemberEvent;
import com.apps.member.model.po.KupaMember;
import com.apps.member.model.po.KupaMemberDownloadGoods;
import com.apps.member.service.IKupaMemberDownloadGoodsService;
import com.apps.member.service.IKupaMemberService;
import com.apps.sannotation.service.SuportService;
import com.apps.sworld.sScript;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Slf4j
@SuportService(service = IKupaMemberService.class)
@Component
public class IKupaMemberScript implements sMemberEvent<KupaMember>
{

    @Autowired
    private IKupaMemberDownloadGoodsService downloadGoodsService;

    /**
     * 用户下载商品的时候添加下载记录
     * @param member_id
     * @param goods_id
     * @param goods
     */
    @Override
    public void onDownloaded(Integer member_id, Integer goods_id, KupaGoods goods)
    {
        //如果不能下载则不进行任何业务处理
        if(null == goods)
            return;
        if(null != downloadGoodsService.getOne(member_id,goods_id))
            return;
        //插入记录
        KupaMemberDownloadGoods downloadGoods = new KupaMemberDownloadGoods();
        downloadGoods.setGoods_id(goods_id);
        downloadGoods.setMember_id(member_id);
        downloadGoods.setGoods_cat_id(goods.getGoods_cat_id());
        downloadGoodsService.saveToDB(downloadGoods);
    }

}
